package com.huizhonglm.diap.widget.expandTab;

import android.content.Context;
import android.util.AttributeSet;
import android.view.LayoutInflater;
import android.view.View;
import android.widget.ListView;
import android.widget.RelativeLayout;

import com.bruce.common.utils.EmptyUtil;
import com.huizhonglm.diap.R;

import java.util.List;


public class MenuListSignle extends RelativeLayout implements MenuBaseAction {

	private MenuInfo[] items;//显示字段
	private OnSelectListener mOnSelectListener;
	private String showText = "item1";

	public String getShowText() {
		return showText;
	}

	public MenuListSignle(Context context, List<MenuInfo> groups) {
		super(context);
		init(context, groups);
	}

	public MenuListSignle(Context context, AttributeSet attrs, int defStyle) {
		super(context, attrs, defStyle);
		init(context, null);
	}

	public MenuListSignle(Context context, AttributeSet attrs) {
		super(context, attrs);
		init(context, null);
	}

	private void init(Context context, List<MenuInfo> groups) {
		if (!EmptyUtil.isEmpty(groups)) {
			items = new MenuInfo[groups.size()];
			for (int i =0; i< groups.size(); i++) {
				MenuInfo info = groups.get(i);
				items[i] = info;
			}
		}

		LayoutInflater inflater = (LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
		inflater.inflate(R.layout.widget_extab_list_signle, this, true);
		setBackgroundResource(R.drawable.bg_dd_menu);
		ListView mListView = (ListView) findViewById(R.id.extab_signle_list);
		MenuListAdapter adapter = new MenuListAdapter(context, items,
				R.drawable.bg_menu_list_signle_s, R.drawable.bg_white_line_bottom);
		adapter.setTextSize(17);
		mListView.setAdapter(adapter);
		adapter.setOnItemClickListener(new MenuListAdapter.OnItemClickListener() {

			@Override
			public void onItemClick(View view, int position) {

				if (mOnSelectListener != null) {
					showText = items[position].getName();
					mOnSelectListener.getValue(items[position]);
				}
			}
		});
	}

	public void setOnSelectListener(OnSelectListener onSelectListener) {
		mOnSelectListener = onSelectListener;
	}

	public interface OnSelectListener {
		void getValue(MenuInfo info);
	}

	@Override
	public void hide() {
		
	}

	@Override
	public void show() {
		
	}

}
